﻿@model LERP.Domain.Order
@using LERP.Domain.Enums
@using LERP.Web.Controllers.ViewModels.OrderViewModels
@using Sharp.Framework 
@using Sharp.Framework.Extensions 

@{
    ViewBag.Title = "订单详情";
    Layout = "~/Views/Shared/_Layout.cshtml";

    var remarks = (List<OrderRemarkViewModel>)ViewBag.Remarks;
    var status = Model.Status;
}  
<div class="empty" style="text-align: left;background-color: #FFFCEB;font-size: 14px;font-family: 宋体,Arial,Lucida,Verdana,Helvetica,sans-serif;">
    
    <strong>订单编号: @this.ViewContext.RouteData.Values["id"] </strong>    <strong>状态: @Model.Status.GetDescription()   </strong> 
</div>
 
    @Html.ValidationSummary(true)
    <fieldset> 
        <legend>基本信息 </legend>
        <ul class="list_form">
            <li>
                @Html.LabelFor(model => model.Customer)  
                    @Model.Customer.Name 
            </li>
        <li>
                @Html.LabelFor(model => model.Contract)  
            @string.Format("[{0}]{1}({2}~{3})", Model.Contract.Code, Model.Contract.Subsidiary.Name, Model.Contract.BeginTime.ToString("yyyy-MM-dd"), Model.Contract.EndTime.ToString("yyyy-MM-dd"))
        </li>
          <li>
               @Html.LabelFor(model => model.OrderDate)   
                   @Model.OrderDate.ToString("yyyy-MM-dd") 
            </li>
        
            <li>
                @Html.LabelFor(model => model.ExpectDelivery)  
                @Model.ExpectDelivery.ToString("yyyy-MM-dd")
            </li>
            @if (status == OrderStatus.ToBeReceived || status == OrderStatus.WaitForReceipt || status == OrderStatus.Receipted || status == OrderStatus.Recount || status == OrderStatus.Close)
            {
                <li>
                    @Html.LabelFor(model => model.TangibleDelivery)  
                    @(Model.TangibleDelivery.HasValue?Model.TangibleDelivery.Value.ToString("yyyy-MM-dd"):"未填写")
                </li>
            } 
            <li>
                @Html.LabelFor(model => model.CustomerOrderNo)    
                    @(string.IsNullOrEmpty(Model.CustomerOrderNo)?"未填写":Model.CustomerOrderNo)   
            </li>
            @if (status == OrderStatus.ToBeShipped || status == OrderStatus.ToBeReceived || status == OrderStatus.Receipted || status == OrderStatus.WaitForReceipt || status == OrderStatus.Recount || status == OrderStatus.Close)
            {
                <li>
                    @Html.LabelFor(model => model.SafeNo)  
                    @(string.IsNullOrEmpty(Model.SafeNo)?"未填写":Model.SafeNo)  
                </li>
                <li>
                    @Html.LabelFor(model => model.DeliveryNo)   
                    @(string.IsNullOrEmpty(Model.DeliveryNo)?"未填写":Model.DeliveryNo)
                </li>
                <li> @Html.LabelFor(model => model.LogisticsProvider) 
                    @(null==Model.LogisticsProvider?"未填写":Model.LogisticsProvider.Name)
                </li>
                <li> @Html.LabelFor(model => model.CarrierCode)  
                    @(string.IsNullOrEmpty(Model.CarrierCode)?"未填写":Model.CarrierCode)   
                </li>

            }
             @if (status == OrderStatus.WaitForReceipt || status == OrderStatus.Receipted || status == OrderStatus.Recount || status == OrderStatus.Close)
             {
                 <li>
                     @Html.LabelFor(model => model.WarehouseCode)   
                     @Model.WarehouseCode
                 </li>
                 <li>
                     <label>验收回单</label>   
                    @(Model.Confirmation ? "已验收" : "未验收")
                 </li>
             }
           
        
           
            <li id="li_Amount" style="display: @((!Model.IsGoods) ? "" : "none");">
                @Html.LabelFor(model => model.Amount)   
                @Html.TextBoxFor(model => model.Amount, new { @class = "text-long" }) 
            </li>
        </ul> 
    </fieldset>
    <fieldset id="fieldset_goods" style="display: @((Model.IsGoods) ? "" : "none");"> 
        <legend>货品明细</legend>
         
       <table class="table_list" id="goods_table" style="width: 99%;">
        <tr>
            <th style="width: 80px;">国际条码</th>
            <th>品名规格</th>
            <th style="width: 80px;">单价</th>
            <th style="width: 30px;">单位</th>
            <th style="width: 60px;">订单数量</th>
             @if (status == OrderStatus.ToBeShipped || status == OrderStatus.ToBeReceived || status == OrderStatus.WaitForReceipt || status == OrderStatus.Recount || status == OrderStatus.Close || status == OrderStatus.Receipted)
             {
                 <th style="width: 60px;">发货数量</th>
             }
            @if (status == OrderStatus.ToBeReceived || status == OrderStatus.WaitForReceipt || status == OrderStatus.Recount || status == OrderStatus.Close || status == OrderStatus.Receipted)
            {
                 <th style="width: 60px;">实收数量</th>
            } 
        </tr>  
           @foreach (var item in Model.Items)
           {
   <tr>
                   <td>@item.Goods.Gencod</td>
                   <td>@item.Goods.Name</td>
                   <td>@item.Price</td>
                   <td>@item.Goods.SellUnit</td>
       <td>@item.OrderNum</td>
         @if (status == OrderStatus.ToBeShipped || status == OrderStatus.ToBeReceived || status == OrderStatus.WaitForReceipt || status == OrderStatus.Recount || status == OrderStatus.Close || status == OrderStatus.Receipted)
         {
                  <td>@item.CarrierNum</td>
         }
            @if (status == OrderStatus.ToBeReceived || status == OrderStatus.WaitForReceipt || status == OrderStatus.Recount || status == OrderStatus.Close || status == OrderStatus.Receipted)
            {
                   <td>@item.ReceivedNum</td>
            } 
               </tr>
           }           
       </table> 
        <div style="float: right;margin-top: 25px; width: 300px;text-align: right;">
            <div style="margin-bottom: 5px;">订单金额: <label id="order_sum">@Model.Items.Sum(x => x.Price * x.OrderNum)</label> 元 
           
            </div>
         
           @if (status != OrderStatus.Draft)
           {
               <div style="margin-bottom: 5px;">发货金额: <label id="order_CarrierAmount">@Model.Amount</label> 元</div>
               if (status != OrderStatus.ToBeShipped)
               {
                   <div style="margin-bottom: 5px;">门店收货金额: <label id="order_PaymentAmount">@Model.PaymentAmount</label> 元</div>
                   <div style="margin-bottom: 5px;">租借出仓金额: <label id="order_WarehouseAmount">@Model.WarehouseAmount</label> 元</div>

               }
           }
     </div>
    </fieldset>

 @if (remarks.Any())
 {
     
       <table class="table_list"  style="width: 99%;">
        <tr>
            <th style="width: 150px;">时间</th> 
            <th>备注内容</th> 
            <th style="width: 80px;  ">操作人</th>
        </tr>
        @foreach (var item in remarks)
        {
           
            <tr > 
                <td>@item.Created.ToString("yyyy-MM-dd hh:mm:ss")</td>
                <td>@item.Action</td>
                <td>@item.UserName</td>  
            </tr>
        }
         
                            
    </table>
 } 
    <br/> 
  
    <br/>
    
<br/>   